package com.project.lk.nurseapp.ticket;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.project.lk.nurseapp.R;
import com.project.lk.nurseapp.common.adapter.BaseRecycleViewAdapter;
import com.project.lk.nurseapp.ticket.model.TicketItemBean;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 功能介绍：
 * 项目名：
 * 模块名称：
 * 作者：LK
 * 日期：2018/1/9
 * 修改日期：
 */
public class TicketListAdapter extends BaseRecycleViewAdapter {
    private int mSelectedItem = -1;
    List<TicketItemBean> mList = new ArrayList<>();
    Context mContext;

    public TicketListAdapter(List<TicketItemBean> list, Context context) {
        this.mList = list;
        this.mContext = context;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_ticket_layout, parent, false);
        ViewHolder viewHolder=new ViewHolder(view);
        return viewHolder;
    }
    public interface OnItemClickListener {
        void setOnItemClickListener(int position,View view);
    }
    private OnItemClickListener mListener;

    public void setItemClick(OnItemClickListener listener) {
        this.mListener = listener;
    }
    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
        ViewHolder viewHolder = (ViewHolder) holder;
//    viewHolder.applyImage.setImageResource(R.mipmap);
        //如果勾选的不是已经勾选状态的Item
        viewHolder.itemView.setSelected(position==mSelectedItem);
        viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mListener.setOnItemClickListener(position, view);
                mSelectedItem = position;
//                notifyItemRangeChanged(0, mList.size());
                notifyDataSetChanged();
            }
        });

    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.item_name)
        TextView itemName;
        @BindView(R.id.item_price)
         TextView itemPrice;

        ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }
}
